package com.example.shopping.dao;

import com.example.shopping.pojo.TypeTemplate;
import com.example.shopping.pojo.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import javax.swing.*;
import java.util.List;

/*
Create by 苍狼 于 2020/1/16
站在巅峰看世界，
落在深渊思人生。
*/
//模板表
@Repository
public interface ITypeTemplateDao {
    //查询模板全部信息
    @Select("select * from type_template")
    @Results(value = {
            @Result(column = "Spec_ids", property = "SpecIds"),
            @Result(column = "brand_ids", property = "brandIds"),
            @Result(column = "Spec_ids.id", property = "specifications", many = @Many(select = "com.example.shopping.dao.ISpecificationOptionDao.selectByOneSpecification", fetchType = FetchType.EAGER)),
            @Result(column = "brand_ids.id", property = "brands", many = @Many(select = "com.example.shopping.dao.IBrandDao.selectByOne", fetchType = FetchType.EAGER))
    })
    List<TypeTemplate> selectTypeTempLateList();

    //新增模板
    @Insert("insert into type_template(name) values(#{name})")
    int insertTypeTemplate(TypeTemplate typeTemplate);

    //删除模板 删除时调用单一查询方法，遍历brand_ids 和Spec_ids 将其id得到 调用规格和品牌的删除方法进行逐一删除
    @Delete("delete from type_template where id=#{id}")
    int deleteTypeTemplate(int id);

    //模糊查询
    @Select("select * from type_template where name like #{name}")
    List<TypeTemplate> selectTypeLateListByLike(String name);

    @Select("select * from type_template where id=#{id}")
    @Options(useGeneratedKeys = true, keyProperty = "SpecIds", keyColumn = "Spec_ids")
    TypeTemplate selectTypeLateById(int id);

    //修改方法
    @Update("update type_template set name=#{name} where id=#{id}")
    int updateTypeLateById(TypeTemplate typeTemplate);
}
